<!DOCTYPE html>
<html>
<head>
<title>Potential Barrier V(x)</title>
<style>
  body {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
    background-color: white;
  }
  canvas {
    background-color: white;
  }
</style>
</head>
<body>
<canvas id="physicsCanvas" width="600" height="450"></canvas>
<script>
const canvas = document.getElementById('physicsCanvas');
const ctx = canvas.getContext('2d');

function draw() {
    ctx.clearRect(0, 0, canvas.width, canvas.height);
    ctx.save(); // Save the default state

    // --- Setup ---
    // Move origin to a convenient location and flip the y-axis so positive is up.
    const originX = canvas.width / 2;
    const originY = 320;
    ctx.translate(originX, originY);
    ctx.scale(1, -1);

    // --- Styles ---
    ctx.strokeStyle = 'black';
    ctx.fillStyle = 'black';
    ctx.lineWidth = 2;

    // --- Axes ---
    const axisLengthX = 260;
    const axisLengthY = 190;
    
    // X-axis
    ctx.beginPath();
    ctx.moveTo(-axisLengthX, 0);
    ctx.lineTo(axisLengthX, 0);
    ctx.stroke();
    // Arrowhead for X-axis
    ctx.beginPath();
    ctx.moveTo(axisLengthX, 0);
    ctx.lineTo(axisLengthX - 12, 5);
    ctx.lineTo(axisLengthX - 12, -5);
    ctx.closePath();
    ctx.fill();
    
    // Y-axis
    ctx.beginPath();
    ctx.moveTo(0, -20); // Start slightly below the x-axis for visual continuity
    ctx.lineTo(0, axisLengthY);
    ctx.stroke();
    // Arrowhead for Y-axis
    ctx.beginPath();
    ctx.moveTo(0, axisLengthY);
    ctx.lineTo(5, axisLengthY - 12);
    ctx.lineTo(-5, axisLengthY - 12);
    ctx.closePath();
    ctx.fill();

    // --- Potential Curve V(x) ---
    // Define key points for the curve
    const a_half = 220;
    const peak_x = 80;
    const peak_y = 150;
    
    ctx.beginPath();
    ctx.moveTo(-a_half, 0);
    // Use two chained Bezier curves to create the asymmetric hill shape with a smooth peak
    ctx.bezierCurveTo(-140, 80, 30, peak_y, peak_x, peak_y);
    ctx.bezierCurveTo(130, peak_y, 200, 60, a_half, 0);
    ctx.stroke();

    // --- Labels ---
    // For drawing text, we need to un-flip the coordinate system temporarily
    // so the text is not drawn upside down.
    ctx.save();
    ctx.scale(1, -1); // Un-flip for text

    // V(x) label
    ctx.font = 'italic 22px Times New Roman';
    ctx.textAlign = 'left';
    ctx.fillText('V(x)', 10, -(axisLengthY - 10)); // Position relative to the top of the axis

    // x label
    ctx.fillText('x', axisLengthX + 10, 10);

    // Origin '0' label
    ctx.font = '20px Times New Roman';
    ctx.textAlign = 'center';
    ctx.fillText('0', -10, 20);

    // -a/2 label
    ctx.fillText('-a/2', -a_half, 25);

    // a/2 label
    ctx.fillText('a/2', a_half, 25);
    
    ctx.restore(); // Restore the drawing coordinate system (y-axis up)

    // --- Caption ---
    ctx.restore(); // Restore the default canvas state (no translate/scale)
    ctx.font = '20px Times New Roman';
    ctx.textAlign = 'center';
    ctx.fillStyle = 'black';
    ctx.fillText('Fig. 1.19', canvas.width / 2, canvas.height - 30);
}

draw();
</script>
</body>
</html>